<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Modules_News_Models_ArticleRelate extends Gio_Core_Model
{
	public function format($row)
	{
		if (isset($row['created_date']) && $row['created_date']) {
			$timeStamp = strtotime($row['created_date']);
			$row['year'] = date('Y', $timeStamp);
			$row['month'] = date('m', $timeStamp);
		}
		
		$json = new Services_JSON();
		$images = $json->decode($row['image_url_data']);
		if (!empty($images)) {
			foreach ($images as $index => $image) {
				$row['image_' . $index] = $image->url;
			}
		}
		
		if (null == trim($row['description']) || trim($row['description']) == '') {
			$string = new Gio_Core_String();
			$description = $string->subString($row['content'], 50);
			$row['description'] = $description;
		}
						
		return $row;
	}
}